define(function(require) {

  var $ = require("jquery");
  var _ = require("underscore");
  var Backbone = require("backbone");
  var Utils = require("utils");
  var Parse = require("parse");
  var AddItemHomePage = require("views/pages/AddItemHomePage");

  var HomePageView = Utils.Page.extend({

    constructorName: "HomePageView",

    //model: HomePageModel,

    initialize: function() {
      // load the precompiled template
      this.template = Utils.templates.homepage;
    },

    id: "homepage",
    className: "i-g page",

    events: {
      
    },

    render: function() {
      $(this.el).html(this.template());

      var Prodotti = Parse.Object.extend("Prodotti");
      var query = new Parse.Query(Prodotti);
      query.find({
          success: function(results) {
                      
            var result= $.parseJSON(JSON.stringify(results));
            for (var i = 0; i < result.length; i++) {
              console.log(result[i]);
              
              $('#listItemHomePage').append(new AddItemHomePage({
                  model: result[i]
              }).render().el);
            }
            
          },
          
          error: function(error) {
            alert("Error: " + error.code + " " + error.message);
            alert("Query fallita");
          }
      });





      return this;
    }
  });

  return HomePageView;

});